package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueFeedbackDao;
import com.prs.crm.domain.crm.Feedback;
import com.prs.crm.domain.doc.IssueFeedback;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.crm.FeedbackService;
import com.prs.crm.service.doc.IssueFeedbackService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class IssueFeedbackServiceImpl extends BaseServiceImpl<IssueFeedback,IssueFeedbackDao> implements IssueFeedbackService{
	private PersonService personService;
	private FeedbackService feedbackService;
	
	@Override
	public void submitIssueFeedback(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> receivePerson = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Feedback> feedbacks = this.getFeedbackService().getFeedbackByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		for(Person person:receivePerson) {
			for(Feedback feedback:feedbacks) {
				IssueFeedback issue = new IssueFeedback();
				issue.setReceivePerson(person);
				issue.setFeedback(feedback);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}

	public FeedbackService getFeedbackService() {
		return feedbackService;
	}

	public void setFeedbackService(FeedbackService feedbackService) {
		this.feedbackService = feedbackService;
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	@Override
	public Collection<IssueFeedback> getValidIssueFeedback(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueFeedback(person);
	}



}
